﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Controls.Message
{
    [ToolboxItem(false)]
    public partial class ErrorIcon : Control
    {
        private Color _borderColor;
        private float _borderThickNess;

        [Browsable(true), Description("边框颜色")]
        [Category("Appearance")]
        public Color BorderColor
        {
            set { _borderColor = value; }
            get { return _borderColor; }
        }

        [Browsable(true), DefaultValue(4.0), Description("边框粗细")]
        [Category("Appearance")]
        public float BorderThickness
        {
            get { return _borderThickNess; }
            set { _borderThickNess = value; }
        }

        public ErrorIcon()
        {
            BorderColor = Color.FromArgb(206, 64, 12);
            BorderThickness = 4;
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            var graphics = pe.Graphics;
            graphics.SmoothingMode = SmoothingMode.AntiAlias;

            Pen pen = new Pen(BorderColor, BorderThickness);
            graphics.DrawEllipse(pen, BorderThickness / 2, BorderThickness / 2, Width - BorderThickness - 1, Height - BorderThickness - 1);

            Brush brush = new SolidBrush(Color.FromArgb(223, 75, 14));
            graphics.FillEllipse(brush, BorderThickness / 2, BorderThickness / 2, Width - BorderThickness - 1, Height - BorderThickness - 1);

            pen = new Pen(Color.White,2);
            float mul = ((float)Width / 32);
            graphics.DrawLine(pen, mul * 9.5f, mul * 10, Width - 9.5f * mul, Height - mul * 10);
            graphics.DrawLine(pen, Width - mul * 9.5f, mul * 10, mul * 9.5f, Height - mul * 10);
        }
    }
}
